package com.liu.handler;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局异常处理类
 */
//@ControllerAdvice
//@ResponseBody  //返回json数据

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NullPointerException.class)
    public Map handler(NullPointerException e) {
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg",e.getMessage());
        return map;
    }

}
